package com.huii.huiiplayer.helper;

import java.util.List;

import services.MyPlayService;
import android.content.Context;
import entities.SongEntity;

public class PlayHelper {

	// Service要用的,我的音乐列表
	private List<SongEntity> myList;

	// 要播放的音乐在列表中的位置
	private int position;
	// 当前音乐在mylist中的位置
	private int currPosition;
	// 上一首的位置
	private int lastPosition;

	private boolean isSingleSong = false;
	private boolean isSongList = false;

	Context mContext;
	MyPlayService service;

	public PlayHelper(Context context) {
		mContext = context;
	}

	public void setSingleSong(SongEntity song) {
		myList.add(0, song);
		isSingleSong = true;
		currPosition = 0;
	}

	public void setListSong(List<SongEntity> list, int position) {
		myList = list;
		isSongList = true;
		currPosition = position;
	}

	public String getSongPath() {
		if (isSingleSong) {
			return myList.get(0).getSongLink();
		} else if (isSongList) {
			return myList.get(position).getSongLink();
		}

		return null;
	}

	public void getNextPosition() {
		// TODO Auto-generated method stub
		if (currPosition == myList.size() - 1) {
			currPosition = 0;
		} else {
			currPosition++;
		}
	}

	public void getLastPosition() {
		// TODO Auto-generated method stub
		int tempPosition = lastPosition;
		lastPosition = currPosition;
		currPosition = tempPosition;
	}

	public void completion() {
		// TODO Auto-generated method stub
		lastPosition = currPosition;
		getNextPosition();
		service.start();
	}

	public PlayHelper attachToService(MyPlayService service) {
		// TODO Auto-generated method stub
		this.service = service;
		return this;
	}
}
